/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package my12306.utils;

import java.awt.Graphics;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;

/**
 *
 * @author Jack
 */
public class ImageUtils {

    public static BufferedImage convertToGrey1(BufferedImage src) {
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
        ColorConvertOp op = new ColorConvertOp(cs, null);
        return op.filter(src, null);
    }

    public static BufferedImage convertToGrey(BufferedImage src) {
        BufferedImage image = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
        Graphics g = image.getGraphics();
        g.drawImage(src, 0, 0, null);
        g.dispose();
        return image;
    }

//    public static BufferedImage convertToGrey3(BufferedImage src) {
//        ImageFilter filter = new GrayFilter(true, 50);
//        ImageProducer producer = new FilteredImageSource(src.getSource(), filter);
//        Toolkit.getDefaultToolkit().createImage(producer);
////        Image mage = this.createImage(producer);
//        return op.filter(src, null);
//    }
}
